const open = "([{"
const close = ")]}"

function check (str) {
  const arr = []
  for (let i = 0; i < str.length; i++) {
    let a = str.charAt(i)
    if (!!~open.indexOf(a)) {
      arr.push(a)
    }
    if (!!~close.indexOf(a)) {
      let b = arr.pop()
      if (close.indexOf(a) !== open.indexOf(b)) {
        return i + 1
      }
    }
  }
  if (arr.length) {
    return str.length
  }
  return 0
}

export default { check }
